package tech.aistar.corejava.day10;

import java.util.Calendar;
import java.util.Date;

/**
 * @Author:         lya
 * @Description:   本类的作用描述:日历类
 * @param
 * @return:
 * @CreateDate:    2019/7/26 12:51
 * @Version:       1.0
*/
public class CalendarDemo {
    public static void main(String[] args) {
        //通过简单工厂模式来构建日历对象
        //Calendar - 抽象类 - 永远是不能够被实例化

        //面向父类编程 - 父类 对象 = new 子类();

        //Calendar cal = new Calendar类的子类();
        Calendar cal = Calendar.getInstance();

        System.out.println(cal);

        //将日历转换成日期
        Date dt = cal.getTime();
        System.out.println(dt);

        //日期转换成日历
        Date at = new Date(System.currentTimeMillis());
        cal.setTime(at);
        System.out.println(cal);

        //重新设置cal
        //根据指定的年月日来构建

        //统一进行赋值
        cal.set(2011,4,5);
        System.out.println(cal.getTime());

        //返回指定日历字段的值
        //int year = cal.get(1);字面量直接赋值 可读性比较差

        int year = cal.get(Calendar.YEAR);
        System.out.println("year = " + year);

        System.out.println(cal.get(Calendar.MONTH));
        System.out.println(cal.get(Calendar.DATE));
        System.out.println(cal.get(Calendar.DAY_OF_MONTH));
        System.out.println(cal.get(Calendar.DAY_OF_WEEK));
        System.out.println(cal.get(Calendar.HOUR));
        System.out.println(cal.get(Calendar.HOUR_OF_DAY));

        System.out.println("===========");

        //可以对单个字符串一一进行赋值
        Calendar dar = Calendar.getInstance();

        //对year进行重新赋值
        //dar.set(1,2015);
        //dar.set(2,2);

        dar.set(Calendar.YEAR,2016);
        dar.set(Calendar.MONTH,5);
        dar.set(Calendar.DATE,25);


    }
}
